package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Employee;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface EmployeeMapper {


    /**
     * 根据用户名查找用户
     * @param employee
     * @return
     */
    @Select("select * from employee where username=#{username}")
    Employee login(Employee employee);

    /**
     * 新增员工
     * @param employee
     * @return
     */
//    @Insert("insert into `employee`(`name`,`username`,phone,sex,id_number) values(#{name},#{username},#{phone},#{sex},#{idNumber})")
//    @Insert("insert  into `employee`(`name`,`username`,`password`,`phone`,`sex`,`id_number`,) values(#{name},#{username},#{password},#{phone},#{sex},#{idNumber}")
    @Insert("insert into employee values(null,#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    Integer addEmployee(Employee employee);

    /**
     * 查询总条数
     * @param
     * @return
     */
    Long count(String name);


    /**
     * 根据名字分页查询
     * @param name
     * @param begin
     * @param pageSize
     * @return
     */
    List<Employee> findAll(@Param("name") String name, @Param("begin") Long begin, @Param("pageSize") Long pageSize);

    /**
     * 根据id查询员工
     * @param id
     * @return
     */
    @Select("select * from employee where id=#{id}")
    Employee selectById(Long id);

    /**
     * 修改员工信息
     * @param employee
     * @return
     */
    @Update("update employee set `username`=#{username},`name`=#{`name`},phone=#{phone},sex=#{sex},id_number=#{idNumber} where`id`=#{`id`}")
    Integer update(Employee employee);
}
